<!--  -->
<template>
    <div>
        <van-form>
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ titledata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号：</span>
                    <span class="titletext">{{ titledata.pmInsId }}</span>
                </div>
            </div>
            <section-header :sectionTitle="'大单奖励评审'" />
          <van-field readonly required name="businessId" :value="fromdata.businessId" label="商机编号：" label-width="5em" />
          <van-field readonly required name="businessName" :value="fromdata.businessName" label="商机名称：" label-width="5em" />
          <van-field readonly required name="customerCode" :value="fromdata.customerCode" label="客户编码：" label-width="5em" />
          <van-field readonly required name="customerName" :value="fromdata.customerName" label="客户单位：" label-width="5em" />
          <van-field readonly name="industryBigTypeProvince" :value="fromdata.industryBigTypeProvince" label="省内行业大类：" label-width="7em" />
          <van-field readonly name="industryBigTypeGroup" :value="fromdata.industryBigTypeGroup" label="集团行业大类：" label-width="7em" />
          <van-field readonly name="industryMinTypeGroup" :value="fromdata.industryMinTypeGroup" label="集团行业小类：" label-width="7em" />
          <van-field readonly name="industryAttribution" :value="fromdata.industryAttribution" label="15大行业名称：" label-width="7.5em" />
          <van-field readonly name="industryNameOneLevel" :value="fromdata.industryNameOneLevel" label="行业一级名称：" label-width="7em" />
          <van-field readonly name="industryNameTwoLevel" :value="fromdata.industryNameTwoLevel" label="行业二级名称：" label-width="7em" />
          <van-field readonly required name="projectName" :value="fromdata.projectName" label="项目名称：" label-width="5em" />
          <van-field readonly required name="projectType" :value="fromdata.projectType" label="项目类型：" label-width="6em" />
          <van-field readonly name="customerAmount" :value="fromdata.customerAmount" label="客户合同金额：" label-width="7em" />
          <van-field readonly name="effectiveAmount" :value="fromdata.effectiveAmount" label="有效签约金额：" label-width="7em" />
          <van-field readonly name="costAmount" :value="fromdata.costAmount" label="成本金额：" label-width="5em" />
          <van-field readonly name="customerPaymentAmount" :value="fromdata.customerPaymentAmount" label="客户回款金额：" label-width="7em" />
          <van-field readonly name="signingDate" :value="fromdata.signingDate" label="客户合同签约日期：" label-width="9em" />
          <van-field readonly name="signingDateContract" :value="fromdata.signingDateContract" label="采购合同签约日期：" label-width="9em" />
          <van-field readonly name="subscriptionDate" :value="fromdata.subscriptionDate" label="订购日期：" label-width="5em" />
          <van-field readonly name="paymentDate" :value="fromdata.paymentDate" label="付款日期：" label-width="5em" />
          <van-field readonly name="rateMargin" :value="fromdata.rateMargin" label="毛利率：" label-width="4em" />
          <van-field readonly name="currentRate" :value="fromdata.currentRate" label="直接收益率：" label-width="6em" />
          <van-field readonly name="treaty" :value="fromdata.treaty" label="协议期回收期比：" label-width="8em" />
          <van-field readonly name="avgMonthly" :value="fromdata.avgMonthly" label="月均收入：" label-width="5em" />
          <van-field readonly name="encourageAndReward" :value="fromdata.encourageAndReward" label="项目总计奖励金额：" label-width="9em" />
          <van-field readonly required name="hasBeenAwarded" :value="fromdata.hasBeenAwarded" label="项目已奖励阶段：" label-width="8em" />
          <van-field readonly name="amountAwarded" :value="fromdata.amountAwarded" label="项目已奖励金额：" label-width="8em" />
          <van-field readonly required name="thisBeenAwarded" :value="fromdata.thisBeenAwarded" label="本次申请奖励阶段：" label-width="9em" />
          <van-field readonly name="thisAward" :value="fromdata.thisAward" label="本次奖励金额：" label-width="7em" />
          <van-field readonly autosize type="textarea" rows="1" name="describe" :value="fromdata.describe" label="其它说明：" label-width="5em" />

            <section-header :sectionTitle="'附件'" />
            <div>
                <van-field readonly required label="客户合同附件:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.contractAnnexFileList" :key="fileitem.id" style="margin-left:20px">
                    <div readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                    </div>
                </div>
                <van-field readonly required label="采购合同附件:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.annexContractFileList" :key="fileitem.id" style="margin-left:20px">
                    <div readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                    </div>
                </div>
                <van-field readonly required label="付款凭证:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.paymentVoucherFileList" :key="fileitem.id" style="margin-left:20px">
                  <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                  </div>
                </div>
                <van-field readonly required label="大单奖励分配表:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.awardFileList" :key="fileitem.id" style="margin-left:20px">
                  <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                  </div>
                </div>
            </div>
            <van-field required readonly autosize type="textarea" rows="1" name="results" v-model="fromdata.results" :value="fromdata.results" label="评审结果：" label-width="5em" :right-icon="canEditCB&&todotype==true? 'arrow' : ''" @click="canEditCB&&todotype==true?showChengbanPick=true:null"/>
            <van-popup v-model="showChengbanPick" position="bottom" get-container="body">
              <van-picker show-toolbar :columns="showChengbanPickcolumns" @confirm="showChengbanPickonConfirm" @cancel="showChengbanPick = false" />
            </van-popup>
            <van-field required v-if="canEditCB == true||fromdata.results" :readonly="!canEditCB&&todotype!=true" autosize type="textarea" rows="1" name="reasonsNo" v-model="fromdata.reasonsNo" :value="fromdata.reasonsNo" label="未通过评审原因：" label-width="8em" :right-icon="canEditCB&&todotype==true? 'arrow' : ''"/>
            <!-- 跳转意见 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#4A90E5; display: inline-block;width:100%;border: 0px solid #4A90E5;border-radius: 15px 0px 0px 15px;
            padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>
            <!-- 流程下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext" :color="canToNext ? '#4A90E5' : '#cccccc'" :style="{display: 'inline-block',width: '100%',border: canToNext ? '0px solid #4A90E5' : '0px solid #cccccc'}" @click="submitFromData()">{{ buttonTitle }}</van-button>
            </div>
        </van-form>
        <!-- 当前办理人 -->
        <section-header v-if="showHistory" :sectionTitle="'当前办理人:'" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>
        <!-- 审批意见 -->
        <section-header id="opinion" :sectionTitle="'审批意见:'" />
        <opinion-item :approveList="approveList" />
    </div>
</template>


<script>
import {
  getRewardReviewByPmInsId,
  getWfLinkTracks,
  getWfOptMags,
  getFormDetail,
} from "@/api/dictapi";
import util from "@/assets/js/public";
import { openFileUrl } from "@/store/openFile";
import { Notify, Toast } from "vant";
import { mapGetters } from "vuex";
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';
import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
export default {
    data() {
        return {
            fromdata: {},
            titledata: {},
            params: this.$route.query,
            todotype: false,
            approveList: [],
            showHistory: false,
            historydata: {},
            toRead: false,
            buttonTitle: '流程下一步',
            canToNext: true,
            canEditCB:false,
            showChengbanPick:false,
            showChengbanPickcolumns:['通过','未通过'],
        };
    },
    computed: {
        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },
    //生命周期--创建完成
    created() {
        if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
          if (this.params.todoType == "1") {
            this.todotype = true;
          }
          else if (this.params.todoType == "2") {
            this.showHistory = true;
          }else if (this.params.todoType == "3") {
            this.toRead = true;
          }
        if (this.params.location == 'dict.start') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持手机端，请至PC办理';
        }
        if (this.params.location == 'dict.startToSupportAssign'||this.params.location=='dict.supportAssignToLeadership'){
          this.canEditCB = true;
        }else {
          this.canEditCB = false;
        }
        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
        SectionHeader,
        OpinionItem

    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {
      tomsg() {
          document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
      },
      showChengbanPickonConfirm(value){
        this.fromdata.results=value;
        this.showChengbanPick=false
      },
      openFileUrlfun(value) {
        this.$router.push(
            {
              name: 'fileview',
              query: {
                openFileUrl: openFileUrl(value)
              }
            }
        );
      },
      getdetail() {
        Toast.loading({
          message: '加载中',
          forbidClick: false
        });
        getFormDetail(Object.assign(this.params, { userName: this.user.userName }))
          .then((result) => {
            if (!result.data) {
              this.onError(result);
              return;
            }
            if (result.data.data) {
              this.titledata = result.data.data
              this.params.pmInsId = result.data.data.pmInsId;
              this.getRewardReviewByPmInsId();//获取第一步信息
            }
          })
          },
          //获取两个number code
      getRewardReviewByPmInsId() {
        getRewardReviewByPmInsId(this.params)
              .then((result) => {
                Toast.clear();
                if (!result.data) {
                  this.onError(result);
                  return;
                }
                if (result.data.data) {
                  this.fromdata = result.data.data;
                }
                if (this.showHistory==true) {
                  this.getWfLinkTracks();
                }else {
                  this.getWfOptMags()
                }
              })
             },getWfLinkTracks() {
              getWfLinkTracks(Object.assign(this.params),{userName:this.user.userName})
                .then((result)=>{
                  Toast.clear();
                  if(!result.data){
                    Notify(result.message);
                    return;
                  }
                  if(result.data.data){
                    //数据过滤，并生成新的数组
                    this.historydata=result.data.data.filter(item=>item.CURRENTSTATE==10)[0]
                    if(this.historydata){
                      if(this.historydata.MANAGER){
                        this.showHistory=true;
                      }else{
                        this.showHistory=false;
                      }
                    }else{
                      this.showHistory=false;
                    }
                  }else{
                    this.showHistory=false;
                  }
                  this.getWfOptMags()
                })
            },
            getWfOptMags() {
              getWfOptMags(Object.assign(this.params), { userName: this.user.userName })
                  .then((result) => {
                    if (!result.data) {
                      Notify(result.message);
                      return;
                    }
                    this.approveList = result.data.data.reverse();
                  })
            },
          submitFromData() { //提交流转
            if(this.params.location=='dict.startToSupportAssign'||this.params.location=='dict.supportAssignToLeadership'){
              if (this.fromdata&&(!this.fromdata.results||this.fromdata.results=='')){
                Notify('请选择评审结果');
                return;
              }
              if (this.fromdata.results=='未通过'&&(!this.fromdata.reasonsNo||this.fromdata.reasonsNo=='')){
                Notify('请填写未通过评审原因');
                return;
              }
            }
            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = this.fromdata;
            formSendData.id = this.titledata.id;
            formSendData.pmInsId = this.titledata.pmInsId;
            formSendData.processType = this.params.pmInsType
            formSendData.workItemId = this.params.workItemId;

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };

            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };

            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                    "notificationId":this.params.todoType==3?this.params.wfnid:"",
                    'processType': this.params.pmInsType,
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormEnhance$api$startSubmitProcess',
                    itemId:this.params.itemId,
                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }));
            this.$router.push({
                name: "srqrsubmit"
            });
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
</style>